package com.xinchen.aiowaste.ui.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import com.xinchen.aiowaste.R
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.JsonUtils
import com.maple.common.widget.view.NumControllerLayout
import com.maple.utils.const.ConstKey
import com.maple.utils.util.LogUtils
import com.maple.utils.util.UIUtils
import com.xinchen.aiowaste.base.BaseActivity
import com.xinchen.aiowaste.vm.PrintLabelViewModel

class PrintLabelActivity : BaseActivity() {

    private var numController: NumControllerLayout? = null

    private val viewModel by viewModels<PrintLabelViewModel>()

    override fun getLayoutId(): Int = R.layout.activity_print_label

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        setTitle("打印标签")
        showClockTime()
        onBackClick()
        numController = findViewById(R.id.num_controller)
        numController?.onShowController(true)
    }

    override fun initData(savedInstanceState: Bundle?) {
        viewModel.defUI.showDialog.observe(this, Observer {
            showLoading()
        })

        viewModel.defUI.dismissDialog.observe(this, Observer {
            dismissLoading()
        })

        viewModel.defUI.toastEvent.observe(this, Observer {
            showToast(it)
        })

        viewModel.labelInfoData.observe(this, Observer{

        })

        getBundle()?.let {
            val type: String = it.getString(ConstKey.BundleKey.EXTRA_TYPE,"")
            val ewmwb: String = it.getString(ConstKey.BundleKey.EXTRA_CODE,"")
            LogUtils.logGGQ("type:${type} -- ewmwb:${ewmwb}")
            LogUtils.logGGQ("ewmwb:${UIUtils.getEwmwb(ewmwb)}")
            val code = UIUtils.getEwmwb(ewmwb)
            viewModel.getLabelInfo(code)
        }
    }
}